<?php

declare(strict_types=1);

namespace App\Entities;

class ProductUnitEntity extends ABaseEntity
{
    public function __construct(ProductUnitModel $model)
    {
        $this->model = $model;
    }

    /**
     * 获取单位名称
     *
     * @return string
     */
    public static function getProductUnitById(int $id)
    {
        $entity = self::find($id);
        if ($entity === null) {
            return '';
        }

        return $entity->getProductUnit();
    }

    /**
     * todo 放入 service
     *
     * @return mixed|string
     */
    public static function getUnitNameByProductSkuId(int $productSkuId)
    {
        $sku = ProductSkuEntity::find($productSkuId);

        return self::getProductUnitById($sku->getProductUnitId());
    }

    /**
     * @return string
     */
    public function getUnitName()
    {
        return (string) $this->model->unit_name;
    }

    /**
     * @return string
     */
    public function getProductUnitNum()
    {
        return (string) $this->model->num;
    }

    /**
     * @return string
     */
    public function getProductUnit()
    {
        return (string) $this->model->unit;
    }
}
